My name is Ying and I make websites with interactive graphics !!!

Let’s make some plots

set.seed(1)

data(nyc_airbnb)
nyc_airbnb = 
  nyc_airbnb %>% 
  mutate(rating = review_scores_location / 2) %>%
  select(
    neighbourhood_group, neighbourhood, rating, price, room_type, lat, long) %>%
  filter(
    !is.na(rating), 
    neighbourhood_group == "Manhattan",
    room_type == "Entire home/apt",
    price %in% 100:500)  %>% 
  sample_n(5000)
# ~ is just tell it is a variable
nyc_airbnb %>%
  mutate(text_label = str_c("Price: $", price, '\nRating: ', rating)) %>% 
  plot_ly(
    x = ~lat, y = ~long, type = "scatter", mode = "markers",
    color = ~price, text = ~text_label, alpha = 0.5)
# the bar chat has to create a dataset for the Y axis to get to the number
common_neighborhoods =
  nyc_airbnb %>% 
  # make each bar the Y score
  count(neighbourhood, sort = TRUE) %>% 
  top_n(8) %>% 
  select(neighbourhood)
## Selecting by n
inner_join(nyc_airbnb, common_neighborhoods, by = "neighbourhood") %>% 
  # reorder of factor with same neighbourhood, but increasing price
  mutate(neighbourhood = fct_reorder(neighbourhood, price)) %>% 
  plot_ly(y = ~price, color = ~neighbourhood, type = "box",
          colors = "Set2")
#Rcolorbrewer
# Figure 3: not just mean and sd, use the spread of the data, to see if the data is skewed or etc... use the existing dataset, not change anything

# juse patch
# don't just use the dashboard for self use only, more deliverable for collaborators to see the data

nyc_airbnb %>% 
  count(neighbourhood) %>% 
  mutate(neighbourhood = fct_reorder(neighbourhood, n)) %>% 
  plot_ly(x = ~neighbourhood, y = ~n, color = ~neighbourhood, type = "bar")
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors